package com.hr.reactive.mono.s02;

import com.hr.reactive.common.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;

import java.util.concurrent.TimeUnit;

/**
 * @author Administrator
 * 延迟执行
 */
public class Lec07FromRunnable {
    private static final Logger log = LoggerFactory.getLogger(Lec07FromRunnable.class);

    public static void main(String[] args) {
       // getProductName(3);
    getProductName(1).subscribe(Utils.subscriber());
        System.out.println("AAA");

    }

   private static Mono<String> getProductName(int productId){
        if(productId==1){
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return Mono.fromSupplier(()->Utils.faker().commerce().productName());
        }
       System.out.println(Thread.currentThread().getName());
       return Mono.fromRunnable(()-> notifyBusiness(productId));
   }
   private static void notifyBusiness(int productId){
       System.out.println(Thread.currentThread().getName());
       log.info("notifyBusiness 不可用:{}",productId);


   }
}
